<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:set var="webroot" value="${pageContext.request.contextPath}" />
<html>
<head>
	<meta charset="utf-8">
	<title>添加成员</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${webroot}/static/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${webroot}/static/css/public.css" media="all" />
	<link rel="stylesheet" href="${webroot}/static/css/topdiv.css" media="all" />
	<style type="text/css">
	.layui-col-xs12 {
    width: 80%;
    }
    .layui-form-select {
     position: relative;
   	 width: 275px;
     }
    .layui-input, .layui-textarea {
    display: block;
    width: 275px;
    padding-left: 10px;
	}
}
	</style>
</head>
<body class="childrenBody">
<%-- <div class="bread">
	<ul><li> 当前位置&nbsp;:</li><li>账号列表</li>&gt;<li><c:if test="${sysUser.userId == null}">添加账号</c:if><c:if test="${sysUser.userId != null}">修改账号</c:if></li></ul>
</div> --%>
<br><br>
<form class="layui-form" style="width:80%;">
	<input type="hidden" id="id" name="id" value="${user.id}" />
	<div class="layui-form-item layui-row layui-col-xs12">
		<label class="layui-form-label">vip结束时间:</label>
		<div class="layui-input-block">
			<input type="text" class="layui-input" id="vipEndTime" placeholder="vip结束时间" lay-key="1">
		</div>
	</div>
	<div class="layui-form-item layui-row layui-col-xs12">
		<label class="layui-form-label">vip等级:</label>
		<div class="layui-input-block newsStatus">
			<select name="isVip" lay-verify="required">
					<c:if test="${user.isVip == 1}">
					    <option selected="selected" value="1">普通会员</option>
					    <option value="2">高级会员</option>
					    <option value="3">企业会员</option>
					</c:if>
					<c:if test="${user.isVip == 2}">
					    <option value="1">普通会员</option>
					    <option selected="selected" value="2">高级会员</option>
					    <option value="3">企业会员</option>
					</c:if>
					<c:if test="${user.isVip == 3}">
					    <option value="1">普通会员</option>
					    <option value="2">高级会员</option>
					    <option selected="selected" value="3">企业会员</option>
					</c:if>
					<c:if test="${user.isVip == null}">
					   	<option value="1">普通会员</option>
					    <option value="2">高级会员</option>
					    <option value="3">企业会员</option>
					</c:if>
			</select>
		</div>
	</div>
	<div class="layui-form-item layui-row layui-col-xs12">
		<div class="layui-input-block">
			<button class="layui-btn" lay-submit="" lay-filter="addUser">提交</button>	
		</div>
	</div>
</form>
<script type="text/javascript" src="${webroot}/static/layui/layui.js"></script>
<script src="${webroot}/static/js/jquery-3.2.1.min.js" charset="utf-8"></script>
<script>
layui.use(['form','layer','laydate'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        table = layui.table;
    
    
	laydate.render({
	    elem: '#vipEndTime', //指定元素
	    type: 'datetime',
	    value: formatDate("${user.vipEndTime}")
	});
    
    form.on("submit(addUser)",function(data){
    	var url = '${webroot}/user/update';
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        // 实际使用时的提交信息
        $.post(url,{
             id : $("#id").val(),  //登录名
             vipEndTime: $("#vipEndTime").val(),  
             isVip : data.field.isVip
         },function(res){
        	 var data=JSON.parse(res);
        	 if(data.success){
        		top.layer.close(index);
  	            top.layer.msg("操作成功");
  	            setTimeout(function(){window.parent.layer.closeAll();},2000);
        	 }else{
        		 top.layer.msg(data.message);
        	 }
        })
        return false;
    })

    function formatDate(date) {
	   if($("#id").val() == "" || $("#id").val()== null || date == "" || date == null){
		   return null;
	   }
	   date =  new Date(date);
	   var datetime = date.getFullYear()
	                + "-"// "年"
	                + ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1))
	                + "-"// "月"
	                + (date.getDate() < 10 ? "0" + date.getDate() : date.getDate())
					+" "+filterTime(date.getHours())+':'+filterTime(date.getMinutes())+':'+filterTime(date.getSeconds());
	    return datetime;
	}
    
    //格式化时间
    function filterTime(val){
        if(val < 10){
            return "0" + val;
        }else{
            return val;
        }
    }
    //定时发布
    var time = new Date();
    var submitTime = time.getFullYear()+'-'+filterTime(time.getMonth()+1)+'-'+filterTime(time.getDate())+' '+filterTime(time.getHours())+':'+filterTime(time.getMinutes())+':'+filterTime(time.getSeconds());
})

</script>
</body>
</html>